package com.iwork.platform.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SpringfoxConfiguration {

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("iWork Web Platform")
                .description("There are all backend API endpoints. You can test any API if you want on here.")
                .termsOfServiceUrl("")
                .version("1.0.0-SNAPSHOT")
                .contact(new Contact("iWork Club", "", "help@iwork.club"))
                .build();
    }

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("^(?!^/error$|^/profile$).*$"))
                .build()
                .apiInfo(apiInfo());
    }

}
